﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="OverridedInstrument.cs" company="">
//   
// </copyright>
// <summary>
//   The overrided instrument.
// </summary>
// --------------------------------------------------------------------------------------------------------------------


using System;
using System.ComponentModel;
using Systemathics.FrameWork;

namespace Systemathics.UserControls
{
    /// <summary>
    /// The overrided instrument.
    /// </summary>
    internal sealed class OverridedInstrument
    {
        private readonly OstCollection osts = new OstCollection();
        private readonly TickerCollection tickers = new TickerCollection();
        private readonly FeesCollection fees = new FeesCollection();

        public OverridedInstrument()
        {
            Tick = 0.1;
            TickValue = 1;
            MaxNominalOrder = 1000;
            isBuyAllowed = true;
            isSellAllowed = true;
            isShortable = true;
            isHardToBorrow = false;
        }

        [Browsable(false)]
        public Guid? ID { get; set; }

        [Category("Instrument"), Description("Common Name, put what you want, this instrument will be referenced in the system by its Name, whatever his Ticker")]
        public string Name { get; set; }

        [Category("Instrument"), Description("In euro. Be carefull all is referenced in Euro")]
        public int? Capitalization { get; set; }

        [Category("Instrument"), Description("Instrument Asset Class")]
        public AssetClass Class { get; set; }

        [Category("Instrument"), Description("Country of Company beholder of Instrument")]
        public Countries Country { get; set; }

        [Category("Instrument"), Description("Currency. All reference prices for currencies are listed in Currency DB. You can view currency table.")]
        [TypeConverter(typeof (CurrencyListConverter))]
        public string Currency { get; set; }

        [Category("Instrument"), Description("Cotation Place of this Instrument")]
        [TypeConverter(typeof (ExchangeListConverter))]
        public string ExchangeName { get; set; }

        [Category("Instrument"), Description("International Security Identification Number")]
        public string ISIN { get; set; }

        [Category("Instrument"), 
         Description("Maturity of this Instrument, if its a Futures or an Option. NULL for Cash Instruments")]
        public DateTime? Maturity { get; set; }

        [Category("Instrument"), Description("Instrument Sector given Eurostoxx activity sectors")]
        public Sectors Sectors { get; set; }

        [Category("Instrument"), Description("Instrument Type")]
        public InstrumentType Type { get; set; }

        [Category("Instrument"), 
         Description("If this Instrument belong to an Index, this is the Ticker of the Index (Cash or Future)")]
        public string BelongToIndex { get; set; }

        [Category("Instrument"), Description("Refinancing value for this Instrument up to now. (Borrowing - Lending) rates thanks to numbers of days in belonging this asset. Can be NULL (Futures)"
             )]
        public int Refinancing { get; set; }

        [Category("Rules"), Description("Minimum possible variation for this Instrument")]
        public double Tick { get; set; }

        [Category("Rules"), Description("When this Instrument moved from a Tick, its representative value in currency is TickValue. IMPORTANT: reported in Instrument Currency. Example: 12.5$ for CME Forex EUR/USD Future"
             )]
        public double TickValue { get; set; }

        [Category("Rules"), 
         Description("Represents in a strategy, the maximum nominal order that can be sent to the market. In Euro. ")]
        public int MaxNominalOrder { get; set; }

        [Category("Rules"), Description("if False, no buy Allowed")]
        public bool isBuyAllowed { get; set; }

        [Category("Rules"), Description("if False, no sell Allowed. IMPORTANT: if False, isShortable will be set False also. The opposite is not true.")]
        public bool isSellAllowed { get; set; }

        [Category("Rules"), Description("if False, no shortable.")]
        public bool isShortable { get; set; }

        [Category("Rules"), Description("if True, no borrowing Allowed")]
        public bool isHardToBorrow { get; set; }

        [Category("Tickers && Events"), TypeConverter(typeof (ExpandableObjectConverter)), 
         Description("List Of Tickers associated with this Instrument depending on each implemented Data/Order Providers.")]
        public TickerCollection Tickers
        {
            get { return tickers; }
        }

        [Category("Tickers && Events"), TypeConverter(typeof(ExpandableObjectConverter)),
         Description("List Of Fees associated with this Instrument depending on each implemented Data/Order Providers.")]
        public FeesCollection Fees
        {
            get { return fees; }
        }

        [Category("Tickers && Events"), TypeConverter(typeof (ExpandableObjectConverter)), Description("List of next events concerning this Instrument")]
        public OstCollection Osts
        {
            get { return osts; }
        }

        public void AddTicker(string Provider, string Ticker)
        {
            tickers.Add(new Ticker {Provider = Provider, Ric = Ticker});
        }

        public void AddOst(DateTime date, string Event, double Value)
        {
            osts.Add(new Ost {Date = date, OstEvent = Event, OstValue = Value});
        }
        public void AddFees(OverridedFees f)
        {
            fees.Add(f);
        }

    }
}